<?php

class Quantri_DmbanController extends Zend_Controller_Action
{

    public function init()
    {
        $option=array(
        		"layout" => "layout",
        		"layoutPath" => APPLICATION_PATH."/layouts/scripts/quantri"
        );
        Zend_Layout::startMvc($option);
        
        $this->view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
    }

    public function indexAction()
    {
        $khuvuc= new Quantri_Model_KhuVuc();
        $this->view->rskhuvuc = $khuvuc->GetAll()->toArray();
        
        $dmban = new Quantri_Model_Dmban();
    	$rsDmban = $dmban->GetAll();
    	
    	$this->view->rsDmban = $rsDmban;
    }

    public function saveAction()
    {
        $this->_helper->layout()->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
        
        $dmban = new Quantri_Model_Dmban();
        
        
        $Id = $this->_request->getParam("idDmban", "-1");
        $Ten = $this->_request->getParam("Ten","");
        $IdKhuVuc = $this->_request->getParam("Khuvuc","");
        $DienGiai = $this->_request->getParam("DienGiai","");
        $ngay = $this->_request->getParam("ngay","");
        $TrangThai = $this->_request->getParam("trangthai","off");
        $_ngay = explode('/', $ngay);
        
        if($TrangThai=="on")
        {$TrangThai = 1;}
        else
        {$TrangThai = 0;}
        
        $dmban->Id = $Id;
        $dmban->Ten = $Ten;
        $dmban->IdKhuVuc = $IdKhuVuc;
        $dmban->DienGiai = $DienGiai;
        $dmban->NgayTao = $_ngay[2] . '-' . $_ngay[1] . '-' . $_ngay[0];
        $dmban->TrangThai = $TrangThai;
        $dmban->save();
    }
    public function xoaAction()
    {
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->viewRenderer->setNoRender(true);
    
    	$dmban = new Quantri_Model_Dmban();
    	$id = $this->_request->getParam("id", "-1");
    
    	$dmban->Xoa($id);
    }
    public function suaAction()
    {     
        
    	$this->_helper->layout()->disableLayout();
    	$this->_helper->viewRenderer->setNoRender(true);
    	
    	$idDmban = $this->_request->getParam("id","-1");
    	
    	$dmban = new Quantri_Model_Dmban();    	
    	$dmban->Id = $idDmban;
    
    	$rsDmban = $dmban->GetById();
    	
    	echo json_encode($rsDmban);
    }
    
    public function locAction()
    {
        $khuvuc= new Quantri_Model_KhuVuc();
        $dmban=new Quantri_Model_Dmban();    
        
    	$this->view->rsKhuvuc = $khuvuc->GetAll()->toArray();
    	
    	$idkhuvuc = $this->_request->getParam("idKhuVuc","-1");
    	
    	$khuvuc->Id=$idkhuvuc;
    	$this->view->rskhuvuc = $khuvuc->GetById();
    	
    	if($idkhuvuc != -1)
    	{
    	$rsDmban = $dmban->GetDmBanKhuVuc($idkhuvuc);
    	}
    	else 
    	{
    	    $rsDmban = $dmban->GetAll();
    	}
    	
    	$this->view->rsDmban = $rsDmban;
    
    	
    }

}



